//添加内容
var addhtml=''
addhtml+='<div class="form-div"><form id="fomr">';
addhtml+='<div class="layui-form-item"><label class="layui-form-label">名称</label><div class="layui-input-block"><input type="text" name="level_name" autocomplete="off" class="layui-input" placeholder="请输入等级名称"></div></div>'
addhtml+='<div class="layui-form-item"><label class="layui-form-label">金额</label><div class="layui-input-block"><input type="text" name="amount" autocomplete="off" class="layui-input" placeholder="请输入等级金额"></div></div>'
addhtml+='<div class="layui-form-item"><label class="layui-form-label">业绩</label><div class="layui-input-block"><input type="text" name="score" autocomplete="off" class="layui-input" placeholder="请输入等级业绩"></div></div>'
addhtml+='<input type="hidden" name="token" value="'+token+'">';
addhtml+='</form></div>';


//编辑内容
var eidthtml=''
eidthtml+='<div class="form-div"><form id="fomr">';
eidthtml+='<input type="hidden" name="id" class="input form-input">';
eidthtml+='<div class="layui-form-item"><label class="layui-form-label">名称</label><div class="layui-input-block"><input type="text" name="level_name" autocomplete="off" class="layui-input"></div></div>'
eidthtml+='<div class="layui-form-item"><label class="layui-form-label">金额</label><div class="layui-input-block"><input type="text" name="amount" autocomplete="off" class="layui-input"></div></div>'
eidthtml+='<div class="layui-form-item"><label class="layui-form-label">业绩</label><div class="layui-input-block"><input type="text" name="score" autocomplete="off" class="layui-input"></div></div>'
eidthtml+='<input type="hidden" name="token" value="'+token+'">';
eidthtml+='</form></div>';


layui.use('table', function() {
	var table = layui.table;
	layer.msg('数据加载中...', {
		icon: 16,
		shade: 0.3,
		success: function() {
			table.render({
				elem: '#centet-cen',
				url:listSrc,
				height: $(".center-tab").height(),
				id:'idTest',
				response: {
		  			statusCode: 1, //成功的状态码，默认：0
				},
				cols: [
					[ //标题栏
						{
							field: 'id',
							title: 'ID',
							sort: true,
							width: 80
						}, {
							field: 'level_name',
							title: '等级',
							width: 150
						}, {
							field: 'amount',
							title: '业绩',
							sort: true,
							width: 150
						}, {
							field: 'member_count',
							title: '会员人数',
							sort: true,
							width: 150
						}, {
							field: 'oper',
							title: '操作',
							toolbar: '#barDemo'
						}
	
					]
				],
				done:function(){
					layer.close(csLoding);
				}
		    });
			layer.close(layer.index)
		}
		
		
	})
	
	
	table.on('tool(table)', function(obj) {
		var data = obj.data;
		if(obj.event === 'del') {
			var id = data.id;
			layer.alert('您确定要删除该等级！',{
				icon: 2,
				btn: ['确定', '关闭'],
				btn1: function(){
					$.ajax({
				    	type:'post',
				    	dataType:'json',
				    	url:delSrc,
				    	data:{
				    		token:token,
				    		id:id
				    	},
				    	success:function(data){
				    		var code=data.code;
				    		var msg=data.msg;
				    		if(code==1){
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 1},function(){
				    				location.reload();
				    			})
				    		}else{
				    			layer.close(layer.index)
				    			layer.alert(msg,{icon: 5})
				    		}
				    	}
				    })
				}
			})
		}else if(obj.event === 'edit') {
			var id=data.id;
			$.ajax({
		    	type:'post',
		    	dataType:'json',
		    	url:seeSrc,
		    	data:{
		    		id:id
		    	},
		    	success:function(data){
		    		var code=data.code;
		    		var msg=data.msg;
		    		if(code==1){
		    			layer.open({
		    			  title:"编辑",
						  type: 1,
						  skin: 'layui-layer-rim',
						  area: ['550px', '290px'],
						  maxmin: true,
			              resize:true,
						  content: eidthtml,
						  btn: ['提交', '关闭'],
						  btn1: function(){
						  	var Adata=$("#fomr").serialize();
						    $.ajax({
						    	type:'post',
						    	dataType:'json',
						    	url:editSrc,
						    	data:Adata,
						    	success:function(data){
						    		var code=data.code;
						    		var msg=data.msg;
						    		if(code==1){
						    			layer.close(layer.index)
						    			layer.alert(msg,{icon: 1},function(){
						    				location.reload();
						    			})
						    		}else{
						    			layer.alert(msg,{icon: 5})
						    		}
						    	}
						    })
						  }
						});
						$("#fomr").formEdit(data.data);
		    		}else{
		    			layer.alert(msg,{icon: 5})
		    		}
		    	}
		    })
			
		}
	});
	
	
})






layui.use('layer', function() {
	var $ = layui.jquery,
		layer = layui.layer;
	var active = {
		add: function() {
			  layer.open({
			  type: 1,
			  title:"新增等级",
			  area: ['550px', '290px'], //宽高
			  maxmin: true,
			  resize:true,
			  content: addhtml,
			  btn: ['提交', '关闭'],
			  btn1: function(){
			  	var Adata=$("#fomr").serialize();
			    $.ajax({
			    	type:'post',
			    	dataType:'json',
			    	url:addSrc,
			    	data:Adata,
			    	success:function(data){
			    		var code=data.code;
			    		var msg=data.msg;
			    		if(code==1){
			    			layer.close(layer.index)
			    			layer.alert(msg,{icon: 1},function(){
			    				location.reload();
			    			})
			    		}else{
			    			layer.alert(msg,{icon: 5})
			    		}
			    	}
			    })
			  }
			});
		}
	}
	$('.right-center').on('click', '.right-btn', function() {
		var othis = $(this),method = othis.data('method');
		active[method] ? active[method].call(this, othis) : '';
	});
})








